package com.project.ssm;

import com.project.ssm.pojo.ApproFileInfo;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import java.io.IOException;
import java.io.Reader;

@Configuration
public class Application {


    @Bean
    public ApproFileInfo approFileInfo(){
        ApproFileInfo approFileInfo = new ApproFileInfo();
        approFileInfo.setBank("ZJKB");
        return approFileInfo;
    }

    @Bean(name = "ZJKB")
    public SqlSession sqlSession1(){
        Reader reader = null;
        try {
            reader = Resources.getResourceAsReader("zjkb_mysql.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        SqlSession session = sqlSessionFactory.openSession(true);
        return session;
    }

    @Bean(name = "WRCB")
    public SqlSession sqlSession2(){
        Reader reader = null;
        try {
            reader = Resources.getResourceAsReader("wrcb_mysql.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        SqlSession session = sqlSessionFactory.openSession(true);
        return session;
    }
}
